﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using XNAProjectLibrary;
using XNAProject.GameElements;
using XNAProject.Core;

namespace XNAProject
{
    public sealed class JoinMenuState : BaseGameState, IJoinMenuState
    {
        private SpriteFont font;

        public JoinMenuState(Game game)
            : base(game)
        {
            game.Services.AddService(typeof(IJoinMenuState), this);        

        }
        public override void Update(GameTime gameTime)
        {
            if (Input.WasPressed(0, Buttons.Start, Keys.Escape))
            {
                GameManager.ChangeState(OurGame.StartMenuState.Value);
            }
            else if (Input.WasPressed(0, Buttons.Start, Keys.Enter))
            {
                Player player = (Player)Game.Services.GetService(typeof(Player));
                player.host = false;
                //player.FirstSynchronize();   
                Game.Services.RemoveService(typeof(IPrepareState));
                OurGame.PrepareState = new PrepareState(OurGame);
                GameManager.ChangeState(OurGame.PrepareState.Value);
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            OurGame.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            OurGame.spriteBatch.DrawString(font, "JoinMenuState \n press ESC for StartMenuState \n press Enter for PlayState", new Vector2(20, 20), Color.White);

            OurGame.spriteBatch.End();

            base.Draw(gameTime);
        }

        protected override void LoadContent()
        {
            font = Content.Load<SpriteFont>(@"Fonts\description");
            base.LoadContent();
        }
    }
}
